<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(comld) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
//$dateTime = date("Y-m-d",strtotime("-1 day"));
//$handle = fopen("http://192.168.0.185/log/test/$dateTime.'a'", "r");
$handle = fopen("/root/backup/log/comld/log.txt", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 10960);
    // $array[] = $buffer;
    $arr = json_decode($buffer, true);
    $id100 = $arr["data"];
    $arr2 = json_decode($id100, true);

    $id101 = $arr2["arrGainFromIAPToday"];
   // $arr3 = json_decode($id101, true);


    $id = $id101["_499cents1"];
    $id2 = $id101["_499cents2"];
    $id3 = $id101["_299cents1"];
    $id4 = $id101["_299cents2"];
    $id5 = $id101["_199cents1"];
    $id6 = $id101["_099cents1"];
    $id6b = $id101["_099cents2"];
    $id7 = $id101["_999cents1"];
    $id8 = $id101["_999cents2"];
    $id9 = $id101["_1999cents2"];
    $id9a = $id101["_1999cents1"];
    $id10 = $id101["_9999cents1"];

    $id11 = $id101["_9999cents2"];  //2
    $id12 = $id101["_4999cents1"];
    $id13 = $id101["_4999cents2"];
    $id14 = $id101["_199cents2"];
   // $id15 = $id101["_299cents2"]; //重复

    $id16 = $arr2["nGoldGainFromGameToday"];
    $id17 = $arr2["nGoldConsumeToday"];
    $id18 = $arr2["nGameOverToday"];

    $id19 = $arr2["arrItemConsumeToday"]; //4
    $id20 = $id19["InnoKillerICT"];
    $id21 = $id19["LandICT"];
    $id22 = $id19["AirStrikeICT"];
    $id23 = $id19["TowerICT"];
    $id24 = $id19["TowerBulletICT"];
    $id25 = $arr2["nLoginTimesToday"];
    $id26 = $arr2["ltWeaponBuyToday"];
    $id26a = $id26["InnoKiller"];
    $id26b = $id26["LandMine"];
    $id26c = $id26["AirStrike"];
    $id26d = $id26["Tower"];
    $id26e = $id26["TowerBullet"];

    $id27 = $arr2["nGoldGainFromIAPToday"];
    $id28 = $arr2["fGameTimeToday"];
    $id29 = $arr2["nTCGainToday"];
    $id30 = $arr2["arrItemBuyToday"];

    $id31 = $id30["InnoKillerIBT"];
    $id32 = $id30["LandMineIBT"];
    $id33= $id30["AirStrikeIBT"];
    $id34 = $id30["TowerIBT"];

    $id35 = $id30["TowerBulletIBT"];  //2
    $id36 = $arr2["nTCConsumeToday"];
    $id37 = $arr2["ltGameBreakOutToday"];
    $id37a = $id37["InnoKiller"];
    $id37b = $id37["LandMine"];
    $id37c = $id37["AirStrike"];
    $id37d = $id37["Tower"];
    $id37e = $id37["TowerBullet"];
    $id38 = $arr2["nStartGameToday"];
    $id39 = $arr2["sFirstGame"];
    $id40 = $arr2["Date"];
    $id41 = $arr2["bCrack"];
    $id42 = $arr2["totalnGoldGainTotal"];
    $id43 = $arr2["totalfGameTimeTotal"];
    $id44 = $arr2["totalnTCGainTotal"];
    $id45 = $arr2["totalarrItem"];
    $id45a = $id45["InnoKillerTAI"];
    $id45b = $id45["LandMineTAI"];
    $id45c = $id45["AirStrikeTAI"];
    $id45d = $id45["TowerTAI"];
    $id45e = $id45["TowerBulletTAI"];

    $id46 = $arr2["totalltWeapon"];
    $id46a = $id46["InnoKiller"];
    $id46b = $id46["LandMine"];
    $id46c = $id46["AirStrike"];
    $id46d = $id46["Tower"];
    $id46e = $id46["TowerBullet"];

    
    $id47 = $arr2["totalnTCNow"];
    $id48 = $arr2["totalarrScene"];
    $id49 = $id48["Credit"];
    $id50 = $id48["Ready"];
    $id51 = $id48["Menu"];
    $id52 = $id48["Map"];
    $id53 = $id48["Help"];
    $id54 = $id48["Option"];
    $id55 = $id48["IAP"];
    $id56 = $id48["Shop"];
    $id57 = $id48["Scene0"];
    $id58 = $id48["Scene1"];
    
    $id59 = $arr2["totalnGoldNow"];

    $id99 = $arr2["macaddress"];
    $id100 = $arr2["gamename"];
    $id101 = $arr["createdate"];

    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
    	
        $_499cents1 = $id;
        $_499cents2 = $id2;
        $_299cents1 = $id3;
        $_299cents2 = $id4;
        $_199cents1 = $id5;
        $_099cents1 = $id6;
        $_099cents2 = $id6b;
        $_999cents1 = $id7;
        $_999cents2 = $id8;
        $_1999cents2 = $id9;
        $_1999cents1 = $id9a;
        $_9999cents1 = $id10;
        $_9999cents2 = $id11;
        $_4999cents1 = $id12;
        $_4999cents2 = $id13;
        $_199cents2 = $id14;
        //$_299cents2 = $id15;
        $nGoldGainFromGameToday = $id16;
        $nGoldConsumeToday = $id17;
        $nGameOverToday = $id18;
        $arrItemConsumeToday = $id19;
        $InnoKiller = $id20;
        $LandMine = $id21;
        $AirStrike = $id22;
        $Tower = $id23;
        $TowerBullet = $id24;
        
         $nLoginTimesToday = $id25;
         $ltWeaponBuyToday = $id26 ;
         $InnoKiller_ltWeaponBuyToday = $id26a;
         $LandMine_ltWeaponBuyToday = $id26b ;
         $AirStrike_ltWeaponBuyToday =$id26c;
         $Tower_ltWeaponBuyToday = $id26d;
         $TowerBullet_ltWeaponBuyToday = $id26e;

         $nGoldGainFromIAPToday = $id27;
         $fGameTimeToday = $id28;
         $nTCGainToday = $id29;
         $arrItemBuyToday = $id30 ;
         $InnoKiller_arrItemBuyToday = $id31;
         $LandMine_arrItemBuyToday =  $id32 ;
         $AirStrike_arrItemBuyToday = $id33;
         $Tower_arrItemBuyToday = $id34;

         $TowerBullet_arrItemBuyToday = $id35;  //2
         $nTCConsumeToday = $id36 ;
         $ltGameBreakOutToday = $id37;
         $nStartGameToday = $id38 ;
         
         $InnoKiller_ltGameBreakOutToday = $id37a;
         $LandMine_ltGameBreakOutToday =  $id37b;
         $AirStrike_ltGameBreakOutToday = $id37c;
         $Tower_ltGameBreakOutToday = $id37d;

         $TowerBullet_ltGameBreakOutToday = $id37e;   
         $FirstLoginTime = $id39; 
         $whatdate = $id40; 
         $Jailbreak = $id41;
         $totalnGoldGainTotal = $id42;
         $totalfGameTimeTotal = $id43;
         $totalnTCGainTotal = $id44;
         $InnoKiller_totalarrItem = $id45a;
         $LandMine_totalarrItem = $id45b;
         $AirStrike_totalarrItem = $id45c;
         $Tower_totalarrItem = $id45d;
         $TowerBullet_totalarrItem = $id45e;
         $totalltWeapon = $id46;
          
         $InnoKiller_totalltWeapon = $id46a;
         $LandMine_totalltWeapon = $id46b;
         $AirStrike_totalltWeapon = $id46c;
         $Tower_totalltWeapon = $id46d;
         $TowerBullet_totalltWeapon = $id46e;

         $totalnTCNow = $id47;
         $totalarrScene = $id48;
         $Credit = $id49;
         $Ready = $id50;
         $Menu = $id51;

         $Map = $id52;
         $Help = $id53;
         $options = $id54;
         $IAP = $id55;
         $Shop = $id56;
         $Scene0 = $id57;
         $Scene1 = $id58;
         $totalnGoldNow = $id59;

         $deviceid = $id99;
         $gamename = $id100;
         $createdate = $id101;
         $date = $id101;
       //var_dump($InnoKiller_arrItemBuyToday);die;

   

        mysql_query("INSERT INTO comld_query (_499cents1,_499cents2,_299cents1,_199cents1,_099cents2,_1999cents1,
                                                _099cents1,_999cents1,_999cents2,_1999cents2,_9999cents1,_9999cents2,
                                                _4999cents1,_4999cents2,_199cents2,_299cents2,nGoldGainFromGameToday,
                                                nGoldConsumeToday,nGameOverToday,arrItemConsumeToday,InnoKiller,LandMine,
                                                AirStrike,Tower,TowerBullet,nLoginTimesToday,ltWeaponBuyToday,nGoldGainFromIAPToday,
                                                fGameTimeToday,nTCGainToday,InnoKiller_arrItemBuyToday,LandMine_arrItemBuyToday,
                                                AirStrike_arrItemBuyToday,Tower_arrItemBuyToday,TowerBullet_arrItemBuyToday,nTCConsumeToday,
                                                ltGameBreakOutToday,nStartGameToday,
                                                FirstLoginTime,whatdate,Jailbreak,
                                                totalnGoldGainTotal,totalfGameTimeTotal,totalnTCGainTotal,InnoKiller_totalarrItem,
                                                LandMine_totalarrItem,AirStrike_totalarrItem,Tower_totalarrItem,TowerBullet_totalarrItem,
                                                totalnTCNow,totalarrScene,Credit,Ready,Menu,Map,
                                                Help,options,IAP,Shop,Scene0,Scene1,totalnGoldNow,totalltWeapon,deviceid,gamename,createdate,date) 
                     VALUES(
                            '$_499cents1',
                            '$_499cents2',
                            '$_299cents1',
                            '$_199cents1',
                            '$_099cents2',
                            '$_1999cents1',
                            '$_099cents1',
                            '$_999cents1',
                            '$_999cents2',
                            '$_1999cents2',
                            '$_9999cents1',
                            '$_9999cents2',
                            '$_4999cents1',
                            '$_4999cents2',
                            '$_199cents2',
                            '$_299cents2',
                            '$nGoldGainFromGameToday',
                            '$nGoldConsumeToday',
                            '$nGameOverToday',
                            '$arrItemConsumeToday',
                            '$InnoKiller',
                            '$LandMine',
                            '$AirStrike',
                            '$Tower',
                            '$TowerBullet',
                            '$nLoginTimesToday',
                            '$ltWeaponBuyToday',

                            '$nGoldGainFromIAPToday',
                            '$fGameTimeToday',
                            '$nTCGainToday',
                            '$InnoKiller_arrItemBuyToday',
                            '$LandMine_arrItemBuyToday',
                            '$AirStrike_arrItemBuyToday',
                            '$Tower_arrItemBuyToday',
                            '$TowerBullet_arrItemBuyToday',
                            '$nTCConsumeToday',

                            '$ltGameBreakOutToday',
                            '$nStartGameToday',
                            '$FirstLoginTime',
                            '$whatdate',
                            '$Jailbreak',
                            '$totalnGoldGainTotal',
                            '$totalfGameTimeTotal',
                            '$totalnTCGainTotal',
                            '$InnoKiller_totalarrItem',
                            '$LandMine_totalarrItem',
                            '$AirStrike_totalarrItem',
                            '$Tower_totalarrItem',
                            '$TowerBullet_totalarrItem',

                            '$totalnTCNow',
                            '$totalarrScene',
                            '$Credit',
                            '$Ready',
                            '$Menu',
                            '$Map',
                            '$Help',
                            '$options',
                            '$IAP',
                            '$Shop',
                            '$Scene0',
                            '$Scene1',
                            '$totalnGoldNow',
                            '$totalltWeapon',
                            '$deviceid',
                            '$gamename',
                            '$createdate',
                            '$date'
)") or die(mysql_error());
    }
}
fclose($handle);
//fclose($fp);
print "Import successful!<br>";

?>
